package com.hy.mydesktop.server.service;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.hy.mydesktop.client.component.type.ComponentControllerEnum;
import com.hy.mydesktop.server.dao.ComponentControllerMetaModelDao;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentControllerMetaModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentControllerMetaNodeModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtAppEventType;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentMetaNodeModel;
import com.hy.mydesktop.shared.persistence.domain.util.ComponentControllerMetaModelUtil;
import com.hy.mydesktop.shared.persistence.domain.util.GxtComponentMetaNodeModelUtil;

@Component("componentControllerMetaModelService")
public class ComponentControllerMetaModelServiceImpl implements ComponentControllerMetaModelService {
	
	private ComponentControllerMetaModelDao componentControllerMetaModelDao;
	
	
	

	/* (non-Javadoc)
	 * @see com.hy.mydesktop.server.service.ComponentControllerMetaModelService#setComponentControllerMetaModelDao(com.hy.mydesktop.server.dao.ComponentControllerMetaModelDao)
	 */
	@Override
	@Resource
	public void setComponentControllerMetaModelDao(
			ComponentControllerMetaModelDao componentControllerMetaModelDao) {
		this.componentControllerMetaModelDao = componentControllerMetaModelDao;
	}

	/* (non-Javadoc)
	 * @see com.hy.mydesktop.server.service.ComponentControllerMetaModelService#addComponentControllerMetaModel(com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentControllerMetaModel)
	 */
	@Override
	public Boolean addComponentControllerMetaModel(GxtComponentControllerMetaModel componentControllerMetaModel) {
		
		return componentControllerMetaModelDao.persist(componentControllerMetaModel);
	}
	
	/* (non-Javadoc)
	 * @see com.hy.mydesktop.server.service.ComponentControllerMetaModelService#addComponentControllerMetaModels(java.util.List)
	 */
	@Override
	public Boolean addComponentControllerMetaModels(List<GxtComponentControllerMetaModel> componentControllerMetaModels) {
		return null;
	}
	/* (non-Javadoc)
	 * @see com.hy.mydesktop.server.service.ComponentControllerMetaModelService#updateComponentControllerMetaModel(com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentControllerMetaModel)
	 */
	@Override
	public Boolean updateComponentControllerMetaModel(GxtComponentControllerMetaModel componentControllerMetaModel) {
		return null;
	}
	
	/* (non-Javadoc)
	 * @see com.hy.mydesktop.server.service.ComponentControllerMetaModelService#updateComponentControllerMetaModels(java.util.List)
	 */
	@Override
	public Boolean updateComponentControllerMetaModels(List<GxtComponentControllerMetaModel> componentControllerMetaModels) {
		return null;
	}
	
	/* (non-Javadoc)
	 * @see com.hy.mydesktop.server.service.ComponentControllerMetaModelService#deleteComponentControllerMetaMode(com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentControllerMetaModel)
	 */
	@Override
	public Boolean deleteComponentControllerMetaMode(GxtComponentControllerMetaModel componentControllerMetaModel) {
		componentControllerMetaModelDao.cascadeRemove(componentControllerMetaModel);
		return true;
	}
	
	@Override
	public Boolean deleteComponentControllerMetaModeById(
			String id) {
		//String queryString ="select o from GxtComponentControllerMetaModel as o where o.id='"+componentControllerMetaModelId+"'";
		//GxtComponentControllerMetaModel gxtComponentControllerMetaModel=(GxtComponentControllerMetaModel)componentControllerMetaModelDao.findUniqueResult(queryString);
		GxtComponentControllerMetaModel gxtComponentControllerMetaModel=(GxtComponentControllerMetaModel)componentControllerMetaModelDao.findById(id);
		
		componentControllerMetaModelDao.cascadeRemove(gxtComponentControllerMetaModel);
		return true;
	}
	
	
	@Override
	public Boolean deleteComponentControllerMetaModeByIdentifier(
			String identifier) {
		GxtComponentControllerMetaModel gxtComponentControllerMetaModel=(GxtComponentControllerMetaModel)componentControllerMetaModelDao.findByIdentifier(identifier);
		componentControllerMetaModelDao.cascadeRemove(gxtComponentControllerMetaModel);

		return true;
	}
	
	
	/* (non-Javadoc)
	 * @see com.hy.mydesktop.server.service.ComponentControllerMetaModelService#findComponentControllerMetaModel(java.lang.String)
	 */
	@Override
	public GxtComponentControllerMetaModel findComponentControllerMetaModel(String componentControllerMetaModelId) {
		return null;
	}
	
	@Override
	public GxtComponentControllerMetaModel findComponentControllerMetaModelByIdentifier(
			String identifier) {
		GxtComponentControllerMetaModel gxtComponentControllerMetaModel = (GxtComponentControllerMetaModel)componentControllerMetaModelDao.findByIdentifier(identifier);
		if (gxtComponentControllerMetaModel==null) {
			return null;
		} else {

			return ComponentControllerMetaModelUtil.reconfigureGxtComponentControllerMetaModelFromJpa(gxtComponentControllerMetaModel);
		}
	
	}

	@Override
	public GxtComponentControllerMetaModel findComponentControllerMetaModelById(
			String id) {
		GxtComponentControllerMetaModel gxtComponentControllerMetaModel = (GxtComponentControllerMetaModel)componentControllerMetaModelDao.findById(id);
		return ComponentControllerMetaModelUtil.reconfigureGxtComponentControllerMetaModelFromJpa(gxtComponentControllerMetaModel);
	
	}

	/* (non-Javadoc)
	 * @see com.hy.mydesktop.server.service.ComponentControllerMetaModelService#findComponentControllerMetaModelByControllerMetaModelId(java.lang.String)
	 */
	@Override
	public GxtComponentControllerMetaModel findComponentControllerMetaModelByControllerMetaModelId(String controllerMetaModelId) {
//		GxtComponentControllerMetaModel gxtComponentControllerMetaModel = (GxtComponentControllerMetaModel)componentControllerMetaModelDao.findByControllerMetaModelId(controllerMetaModelId);
		GxtComponentControllerMetaModel gxtComponentControllerMetaModel = (GxtComponentControllerMetaModel)componentControllerMetaModelDao.findByControllerMetaModelId(controllerMetaModelId);
		return ComponentControllerMetaModelUtil.reconfigureGxtComponentControllerMetaModelFromJpa(gxtComponentControllerMetaModel);
	
	}
	
	/* (non-Javadoc)
	 * @see com.hy.mydesktop.server.service.ComponentControllerMetaModelService#findComponentControllerMetaModeByUserId(java.lang.String)
	 */
	@Override
	public List<GxtComponentControllerMetaModel> findComponentControllerMetaModeByUserId(String userId) {
		return null;
	}

	@Override
	public List<GxtComponentControllerMetaModel> findAllComponentControllerMetaModels() {
		List<GxtComponentControllerMetaModel> controllerMetaModels= componentControllerMetaModelDao.find();
		return ComponentControllerMetaModelUtil.reconfigureGxtComponentControllerMetaModelsFromJpa(controllerMetaModels);
		
		//return controllerMetaModels;
	
	}

	

	
	



}
